import { fetchCoinFlowList } from "../../api/modules/payment";
import { getPlayLogList } from "../../api/modules/play";
import { APP_ID, CLIENT, PlATFORM } from "../../config";
import { loginController } from "../../utils/login";
import { accSub } from "../../utils/number.utils";
Page({
  data: {
    isDeleteModel:false,
    list: [],
    bottomLoading: false
  },
  loading: false,
  pageable: {
    total: 0,
    pageSize: 9,
    pageNum: 1
  },
  onLoad: async function () {
    this.fetchData(1)
  },
  onPullDownRefresh() {
    this.fetchData(1, () => {
      tt.stopPullDownRefresh({});
    })
  },
  onReachBottom() {
    if (this.data.list.length >= this.pageable.total) return;
    this.fetchData(this.pageable.pageNum + 1);
  },
  async fetchData(pageNum, cb) {
    if (this.loading) return;
    this.loading = true;
    this.setData({
      bottomLoading: pageNum !== 1
    })
    try {
      await loginController.login()
      const {
        data
      } = await getPlayLogList({
        pageNum,
        pageSize: this.pageable.pageSize,
        platform:PlATFORM,
        "app-id":APP_ID,
        "client":CLIENT
      });
      let {
        list,
        ...pageable
      } = data;
      this.pageable = pageable;
      // list = (list || []).map(v=>{
      //   return {
      //     label:v.beforeAmount>v.afterAmount?"消费":"充值",
      //     num:accSub(v.afterAmount,v.beforeAmount),
      //     createdAt:v.createdAt
      //   }
      // });
      
      this.setData({
        list: pageNum === 1 ? list : this.data.list.concat(list)
      })

      if (this.data.list.length >= this.pageable.total && pageNum !== 1) {
        tt.showToast({
          title: '到底了～～'
        });
      }
    } catch {

    } finally {
      this.loading = false;
      this.setData({
        bottomLoading: false
      })
      typeof cb === 'function' && cb()
    }

  },
})